package com.jsyl.lwbk.web.controller.business;

import com.jsyl.lwbk.business.dto.ChildReportDTO;
import com.jsyl.lwbk.business.dto.ReportTableDTO;
import com.jsyl.lwbk.business.handle.CalculateEvaluateScoreHandle;
import com.jsyl.lwbk.business.handle.CreateEvaluateReportPDFHandle;
import com.jsyl.lwbk.business.service.IChildService;
import com.jsyl.lwbk.business.service.IEvaluateReportService;
import com.jsyl.lwbk.business.vo.ChildReportVO;
import com.jsyl.lwbk.common.core.controller.BaseController;
import com.jsyl.lwbk.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(value = "小孩档案")
@Controller
@RequestMapping("business/childReport")
public class ChildReportController extends BaseController {

    private String prefix = "business/childEvaluate";

    @Autowired
    IChildService childService;
    @Autowired
    IEvaluateReportService evaluateReportService;
    @Autowired
    CalculateEvaluateScoreHandle calculateEvaluateScoreHandle;
    @Autowired
    CreateEvaluateReportPDFHandle createEvaluateReportPDFHandle;

    @ApiOperation(value = "获取小孩报告")
    @ApiImplicitParams({@ApiImplicitParam(name = "childId", value = "小孩id")})
    @RequiresPermissions("business:evaluateReportFlag:view")
    @GetMapping("/childReport/{childId}")
    public String childReport(@PathVariable("childId") Long childId, ModelMap mmap) {
        mmap.put("childId", childId);
        return prefix + "/childReport";
    }

    @ApiOperation(value = "获取小孩报告List")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "childId", value = "小孩id"),
            @ApiImplicitParam(name = "evaluateNumber", value = "测评编号"),
            @ApiImplicitParam(name = "questionId", value = "题目id"),
            @ApiImplicitParam(name = "answerSore", value = "答案分数"),
            @ApiImplicitParam(name = "selectCenterId", value = "中心id")
    })
    @RequiresPermissions("business:child:list")
    @PostMapping("/findChildReportList")
    @ResponseBody
    public TableDataInfo findChildReportList(ChildReportDTO childReportDTO) {
        startPage();
        List<ChildReportVO> list = evaluateReportService.getChildReport(childReportDTO);
        return getDataTable(list);
    }

    @ApiOperation(value = "获取报告")
    @ApiImplicitParams({@ApiImplicitParam(name = "evaluateNumber", value = "测评编号")})
    @RequiresPermissions("business:childReport:getReport")
    @GetMapping("/reportTable/{evaluateNumber}")
    public String getReport(@PathVariable("evaluateNumber") String evaluateNumber, ModelMap mmap) {
        ReportTableDTO reportTableDTO = evaluateReportService.getReportTableDTO(evaluateNumber);
        mmap.put("reportTableDTO", reportTableDTO);
        return "business/template/" + reportTableDTO.getEvaluateVersion() + "/reportTable";
    }

    @ApiOperation(value = "获取报告DPF的地址")
    @ApiImplicitParams({@ApiImplicitParam(name = "evaluateNumber", value = "测评编号")})
    @RequiresPermissions("business:childReport:download")
    @GetMapping("/getReportPdfUrl/{evaluateNumber}")
    @ResponseBody
    public String getReportPdfUrl(@PathVariable("evaluateNumber") String evaluateNumber) {
        String url = createEvaluateReportPDFHandle.getEvaluateReportUrl(evaluateNumber);
        return url;
    }

    @PostMapping("/test")
    @ResponseBody
    public String test() {
        calculateEvaluateScoreHandle.handle("20201226171153","");
        return "xxxx";
    }
}
